package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * 扑克牌游戏的逻辑
 */
@SuppressWarnings({"all"})
public class Game {

    private static final String[] suits = {"♥", "♠", "■", "♣"};

    // 初始化牌
    public List<Poker> buyPoker(){
        List<Poker> pokers = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Poker poker = new Poker(j, suits[i]);
                pokers.add(poker);
            }
        }
        return pokers;
    }

    // 打乱牌
    public void shuffle(List<Poker> pokers){
//        Collections.shuffle(pokers);可以使用集合工具类直接打乱
        for (int i = pokers.size()-1; i > 0; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap(pokers, i, index);
        }
    }

    // 交换牌
    public void swap(List<Poker> pokers, int i, int j){
        Poker temp = pokers.get(i);
        pokers.set(i, pokers.get(j));
        pokers.set(j, temp);
    }

    // 揭牌
    public List<List<Poker>> game(List<Poker> pokers){
        //存储三个人的牌
        List<List<Poker>> person = new ArrayList<>();

        // 三个人都有牌
        List<Poker> person1 = new ArrayList<>();
        List<Poker> person2 = new ArrayList<>();
        List<Poker> person3 = new ArrayList<>();
        person.add(person1);
        person.add(person2);
        person.add(person3);

        // 轮流抓牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Poker removePoker = pokers.remove(0); // 每揭牌一张 删除一张
                person.get(j).add(removePoker);
            }
        }

        return person;
    }
}
